package com.movitech.mobile.cz.base.purchase.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.purchase.entity.PStrategicPurchasePlan;
import com.movitech.mobile.cz.base.purchase.service.PStrategicPurchasePlanService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * PStrategicPurchasePlan 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@RestController
@RequestMapping("/v1/pStrategicPurchasePlan")
public class PStrategicPurchasePlanController {
    @Autowired
    private PStrategicPurchasePlanService pStrategicPurchasePlanService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有战略采购规划接口",
            notes = "获取所有战略采购规划接口",
            response = PStrategicPurchasePlan.class
    )
    public RestReturnResult list() {
        RestReturnResult restResult = RestReturnResult.success();
        Page<PStrategicPurchasePlan> page = pStrategicPurchasePlanService.selectPage(new Page<PStrategicPurchasePlan>());
        restResult.setData(page);
        return restResult;
    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "战略采购规划列表查询接口",
            notes = "战略采购规划列表查询接口",
            response = PStrategicPurchasePlan.class
    )
    public RestReturnResult searchList(@RequestBody PStrategicPurchasePlan pStrategicPurchasePlan,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
        RestReturnResult restResult = RestReturnResult.success();
        Page<PStrategicPurchasePlan> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(pStrategicPurchasePlan);
        page = pStrategicPurchasePlanService.selectPage(page,wrapper);
        restResult.setData(page);
        return restResult;
    }

    @GetMapping("/getPStrategicPurchasePlan/{id}")
    @ApiOperation(
            value = "战略采购规划对象ID获取接口",
            notes = "战略采购规划对对象ID获取接口",
            response = PStrategicPurchasePlan.class
    )
    public RestReturnResult addPStrategicPurchasePlan(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        PStrategicPurchasePlan pStrategicPurchasePlan = pStrategicPurchasePlanService.selectById(id);
        restResult.setData(pStrategicPurchasePlan);
        return restResult;
    }

    @PostMapping("/add")
    @ApiOperation(
            value = "战略采购规划添加接口",
            notes = "战略采购规划添加接口",
            response = PStrategicPurchasePlan.class
    )
    public RestReturnResult add(@RequestBody PStrategicPurchasePlan pStrategicPurchasePlan) {
        RestReturnResult restResult = RestReturnResult.success();
        pStrategicPurchasePlanService.insert(pStrategicPurchasePlan);
        restResult.setData(pStrategicPurchasePlan);
        return restResult;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "战略采购规划更新接口",
            notes = "战略采购规划更新接口",
            response = PStrategicPurchasePlan.class
    )
    public RestReturnResult update(@RequestBody PStrategicPurchasePlan pStrategicPurchasePlan) {
        RestReturnResult restResult = RestReturnResult.success();
        pStrategicPurchasePlanService.updateById(pStrategicPurchasePlan);
        restResult.setData(pStrategicPurchasePlan);
        return restResult;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(
            value = "战略采购规划通过ID删除接口",
            notes = "战略采购规划通过ID删除接口",
            response = PStrategicPurchasePlan.class
    )
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        pStrategicPurchasePlanService.deleteById(id);
        return restResult;
    }


}

